from WebSite.tools.readExcel import ExcelTool


class ReadCase(object):

    @staticmethod
    def read_case(excel_name, sheet_name, case_name):
        """
        读取excel并请求
        :param excel_name: 传入入excel名称
        :param sheet_name: sheet名称
        :param case_name: 用例名称
        :return:
        """
        size = len(ExcelTool().get_xls(excel_name, sheet_name))
        mlsheet = ExcelTool().get_xls(excel_name, sheet_name)  # 读取excel信息
        case = []
        count = 0
        for i in range(0, size):
            if mlsheet[i][2] == case_name:  # 读取指定指定用例名称的数据
                case.append(mlsheet[i])
                count += 1
                if count > 1:
                    case.clear()
                    print('检测到%d个同名用例，请核对excel' % count)
                    break
        return case


if __name__ == '__main__':
    a = ReadCase()
    print(a.read_case('test_case.xls', 'Sheet1', 'UserLogin'))
